<?php

/**
 * This is the model class for table "{{waitbuyer}}".
 *
 * The followings are the available columns in table '{{waitbuyer}}':
 * @property string $id
 * @property string $tid
 * @property string $alipay_no
 * @property string $buyer_nick
 * @property integer $created
 * @property string $receiver_mobile
 * @property string $receiver_name
 * @property string $receiver_state
 * @property string $receiver_city
 * @property string $receiver_district
 * @property string $receiver_address
 * @property string $receiver_zip
 * @property integer $uptime
 */
class Waitbuyer extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Waitbuyer the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'taobao_waitbuyer';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('created, uptime', 'numerical', 'integerOnly'=>true),
			array('tid, alipay_no, buyer_nick, receiver_mobile, receiver_name, receiver_state, receiver_city, receiver_district', 'length', 'max'=>50),
			array('receiver_address', 'length', 'max'=>255),
			array('receiver_zip', 'length', 'max'=>10),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, tid, alipay_no, buyer_nick, created, receiver_mobile, receiver_name, receiver_state, receiver_city, receiver_district, receiver_address, receiver_zip, uptime', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'tid' => 'Tid',
			'alipay_no' => 'Alipay No',
			'buyer_nick' => 'Buyer Nick',
			'created' => 'Created',
			'receiver_mobile' => 'Receiver Mobile',
			'receiver_name' => 'Receiver Name',
			'receiver_state' => 'Receiver State',
			'receiver_city' => 'Receiver City',
			'receiver_district' => 'Receiver District',
			'receiver_address' => 'Receiver Address',
			'receiver_zip' => 'Receiver Zip',
			'uptime' => 'Uptime',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('tid',$this->tid,true);
		$criteria->compare('alipay_no',$this->alipay_no,true);
		$criteria->compare('buyer_nick',$this->buyer_nick,true);
		$criteria->compare('created',$this->created);
		$criteria->compare('receiver_mobile',$this->receiver_mobile,true);
		$criteria->compare('receiver_name',$this->receiver_name,true);
		$criteria->compare('receiver_state',$this->receiver_state,true);
		$criteria->compare('receiver_city',$this->receiver_city,true);
		$criteria->compare('receiver_district',$this->receiver_district,true);
		$criteria->compare('receiver_address',$this->receiver_address,true);
		$criteria->compare('receiver_zip',$this->receiver_zip,true);
		$criteria->compare('uptime',$this->uptime);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
	protected function beforeSave() {
	parent::beforeSave();
		if($this->isNewRecord){
			$this->uptime = time();
		}
	return true;
	}
}